home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Toolbox
/
Visual Basic Toolbox (P.I.E.)(1996).ISO
/
toolbar
/
databar
/
psidctb.ba_
/
psidctb.ba
Wrap
Text File
|
1995-03-30
|
6KB
|
211 lines
'
' Copyright ⌐ 1994-1995, Proficient Solutions Inc.
'
' Project: PSIDataBar Support routines
' Author : mj
' Date : 15 March 1995
'
' File : PSIDCTB.Bas
' Purpose: Contains PSIDataBar constants and some useful Windows
' routines for controlling forms and fields.
'
' Programmer's Notes:
'
'
Option Explicit
' Toolbar Action commands
Global Const TB_ACTION_ADDNEW = 0
Global Const TB_ACTION_DELETE = 1
Global Const TB_ACTION_UPDATE = 2
Global Const TB_ACTION_UPDATECONTROLS = 3
Global Const TB_ACTION_EDIT = 4
Global Const TB_ACTION_MOVEFIRST = 5
Global Const TB_ACTION_MOVEPREVIOUS = 6
Global Const TB_ACTION_MOVENEXT = 7
Global Const TB_ACTION_MOVELAST = 8
'Global Const TB_ACTION_MARKRECORD = 9
'Global Const TB_ACTION_RETURN = 10
'Global Const TB_ACTION_LASTEDIT = 11
Global Const TB_ACTION_INIT = 9
' Border styles
Global Const TB_BORDERNONE = 0
Global Const TB_BORDERSINGLE = 1
Global Const TB_BORDERRAISED = 2
Global Const TB_BORDERLOWERED = 3
' Alignment styles
Global Const TB_ALIGNNONE = 0
Global Const TB_ALIGNTOP = 1
Global Const TB_ALIGNBOTTOM = 2
'Global Const TB_ALIGNLEFT = 3
'Global Const TB_ALIGNRIGHT = 4
'Global Const TB_ALIGNFLOAT = 5
' Toolbar Button indices
Global Const TB_BUTTON_ADDNEW = 0
Global Const TB_BUTTON_DELETE = 1
Global Const TB_BUTTON_UPDATE = 2
Global Const TB_BUTTON_UPDATECONTROLS = 3
Global Const TB_BUTTON_EDIT = 4
Global Const TB_BUTTON_MOVEFIRST = 5
Global Const TB_BUTTON_MOVEPREVIOUS = 6
Global Const TB_BUTTON_MOVENEXT = 7
Global Const TB_BUTTON_MOVELAST = 8
'Global Const TB_BUTTON_MARKRECORD = 9
'Global Const TB_BUTTON_RETURN = 10
'Global Const TB_BUTTON_LASTEDIT = 11
' Useful Windows messages
Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
Declare Function SetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal wNewWord As Integer) As Integer
Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wcmd As Integer) As Integer
Declare Function EnableWindow Lib "User" (ByVal hWnd As Integer, ByVal abool As Integer) As Integer
' Things the Window's API really wants (not those weird VB versions)
Global Const WINAPI_TRUE = 1
Global Const WINAPI_FALSE = 0
' Things we ask of and tell a control's window
Global Const WM_USER = &H400
Global Const EM_SetReadOnly = (WM_USER + 31)
Global Const EM_LIMITTEXT = (WM_USER + 21)
' offset to get the window style
Global Const GWL_STYLE = -16
' Used for tweaking the acceptable case for an edit control
Global Const ES_UPPERCASE = &H8&
Global Const ES_LOWERCASE = &H10&
'
' Centers window in its parent
'
Sub CenterWindow (Parent As Form, Child As Form)
Dim newTop As Integer
Dim newLeft As Integer
newTop = (Abs(Parent.Height - Child.Height) / 2) + Parent.Top
newLeft = (Abs(Parent.Width - Child.Width) / 2) + Parent.Left
Child.Move newLeft, newTop
End Sub
'
' Sets a ComboBox control to read-only with a gray background,
' but keeps the text color "normal"
'
Sub SetComboReadOnly (Ctl As Control)
Dim l As Long, hWnd As Integer, last As Integer
' get the first child window of the combo box
hWnd = GetWindow(Ctl.hWnd, 5)
' find the last child of the combo box
' the last child is the edit control
' this appears to be quite a reliable assumption
Do
last = hWnd
hWnd = GetWindow(last, 2)
Loop Until hWnd = 0
hWnd = last
If hWnd <> 0 Then l = SendMessage(hWnd, EM_SetReadOnly, WINAPI_TRUE, 0&)
' disable the combo box
Ctl.Enabled = False
' enable the edit - get its foreground color back to normal
If hWnd <> 0 Then hWnd = EnableWindow(hWnd, WINAPI_TRUE)
Ctl.BackColor = &HC0C0C0
End Sub
'
' re-enables a combo box and changes its background
' color back to white
'
Sub SetComboReadWrite (Ctl As Control)
Dim l As Long, hWnd As Integer, last As Integer
' get the first child window of the combo box
hWnd = GetWindow(Ctl.hWnd, 5)
' find the last child of the combo box
' the last child is the edit control
' this appears to be quite a reliable assumption
Do
last = hWnd
hWnd = GetWindow(last, 2)
Loop Until hWnd = 0
hWnd = last
If hWnd <> 0 Then l = SendMessage(hWnd, EM_SetReadOnly, WINAPI_FALSE, 0&)
' enable combobox
Ctl.Enabled = True
Ctl.BackColor = &H80000005
End Sub
'
' Changes a TextEdit control to read-only and
' makes the background grey a'la Windows 95
'
Sub SetEditReadOnly (EditCtl As TextBox)
Dim result As Long
result = SendMessage(EditCtl.hWnd, EM_SetReadOnly, WINAPI_TRUE, 0&)
' set the back ground to medium gray
EditCtl.BackColor = &HC0C0C0
End Sub
'
' Changes a TextBox so that it's editable
' and appears as an action area
'
Sub SetEditReadWrite (EditCtl As TextBox)
Dim result As Long
result = SendMessage(EditCtl.hWnd, EM_SetReadOnly, WINAPI_FALSE, 0&)
' set the background to white
EditCtl.BackColor = &H80000005
End Sub
'
' forces the text in an edit control to be
' all lowercae
'
Sub SetLowerCaseOnly (EditCtl As TextBox)
Dim WindowLong As Long
WindowLong = GetWindowLong(EditCtl.hWnd, GWL_STYLE)
WindowLong = WindowLong Or ES_LOWERCASE
WindowLong = SetWindowLong(EditCtl.hWnd, GWL_STYLE, WindowLong)
End Sub
'
' forces the text in an edit control to be
' all uppercase
'
Sub SetUpperCaseOnly (EditCtl As TextBox)
Dim WindowLong As Long
WindowLong = GetWindowLong(EditCtl.hWnd, GWL_STYLE)
WindowLong = WindowLong Or ES_UPPERCASE
WindowLong = SetWindowLong(EditCtl.hWnd, GWL_STYLE, WindowLong)
End Sub